<template>
  <div class="player-cpn">
    <div class="left" @click="handlePlaypage">
      <img
        :src="store.state.musicInfo.al.picUrl"
        alt=""
        :class="store.state.isPlayer ? 'xuanzhuan' : 'xuanzhuanzt'"
      />
      <div class="al">{{ store.state.musicInfo.name }} -</div>
      <div class="ar">
        <span v-for="item in store.state.musicInfo.ar" :key="item.id"
          >{{ item.name }}
        </span>
      </div>
    </div>
    <div class="right">
      <van-circle
        v-model:current-rate="currentRate"
        :stroke-width="20"
        layer-color="#E6E6E6"
        color="#333333"
        size="30px"
        style="line-height: 34px; margin-right: 20px"
      >
        <template #default>
          <van-icon
            name="play"
            size="20px"
            color="#333333"
            @click="play"
            v-if="!store.state.isPlayer"
          />

          <van-icon
            name="pause"
            size="20px"
            color="#333333"
            @click="play"
            v-else
          />
        </template>
      </van-circle>
      <i
        class="iconfont icon-24gf-playlist2"
        style="font-size: 20px"
        @click="showPlayList"
      ></i>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
const store = useStore()
const router = useRouter()
const globalAudio = store.state.globalAudio

const currentRate = computed(() => {
  return store.state.parvalue
})
//播放按钮
const play = () => {
  if (store.state.isPlayer) {
    // 暂停
    globalAudio.pause()
    store.commit('CHANGE_PLAYER', false)
    console.log('暂停了')
  } else {
    // 播放
    console.log(globalAudio)
    globalAudio.play()
    store.commit('CHANGE_PLAYER', true)
  }
}
const handlePlaypage = () => {
  router.push({
    path: '/playpage',
    query: {
      encodeId: store.state.musicInfo.id
    }
  })
}

//显示播放列表
const showPlayList = () => {
  store.commit('CHANGE_PLAYLIST', true)
}
</script>
<style lang="scss" scoped>
.player-cpn {
  background-color: #fff;
  height: 50px;
  // background-color: red;
  position: fixed;
  bottom: 50px;
  display: flex;
  justify-content: space-between;
  align-content: center;
  width: 100%;
  border-top: 1px solid #e9e8e8;
  padding: 0 15px;
  box-sizing: border-box;
  .left {
    display: flex;
    align-items: center;
    img {
      width: 28px;
      height: 28px;
      border: 8px solid #000;
      border-radius: 50%;
      position: relative;
      top: -10px;
    }
    .al {
      margin-left: 10px;
      color: #333333;
      font-size: 14px;
    }
    .ar {
      margin-left: 10px;
      color: #666666;
      font-size: 12px;
    }
  }
  .right {
    display: flex;
    align-items: center;
  }
}

.xuanzhuan {
  animation: rotate 30s linear infinite;
}

.xuanzhuanzt {
  animation: rotate 30s linear infinite;
  animation-play-state: paused;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(359deg);
  }
}
</style>
